package com.yuerenjf.yuerenjinfu.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;


import com.nostra13.universalimageloader.core.ImageLoader;
import com.umeng.analytics.MobclickAgent;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.yuerenjf.yuerenjinfu.R;


//邀请二维码
public class MyCodeActivity extends BaseActivity {

    String url;


    private TextView mMycode_share_text;
    private ImageView mMycode_image;
    private TextView mMycode_num_text;

    private String code;
    private String imageUrl;

    public static void launchActivity(Context context, String code,String imageUrl) {
        Intent intent = new Intent(context, MyCodeActivity.class);
        intent.putExtra("code", code);
        intent.putExtra("imageUrl", imageUrl);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        tv_title.setText("邀请码");

//        MobSDK.init(MyCodeActivity.this);
        ll_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        code = getIntent().getStringExtra("code");
        imageUrl = getIntent().getStringExtra("imageUrl");
        mMycode_num_text.setText(code);


        ImageLoader.getInstance().displayImage(imageUrl,mMycode_image);
        mMycode_share_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                ShareDialog dialog=new ShareDialog(MyCodeActivity.this);
//                dialog.setContent("我的邀请码","",imageUrl,"");
//                dialog.showShareDialog();
                UMImage umImage = new UMImage(MyCodeActivity.this, imageUrl);
//                UMWeb web = new UMWeb(loadUrl);
//                web.setTitle(title);//标题
//                web.setThumb(umImage);  //缩略图
//                web.setDescription(desc);//描述

                new ShareAction(MyCodeActivity.this)
//                        .withMedia(web)
                        .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE, SHARE_MEDIA.QQ)

                        .setCallback(shareListener).open();

            }
        });
    }


    private void bindViews(View view) {

        mMycode_share_text = (TextView) view.findViewById(R.id.mycode_share_text);
        mMycode_image = (ImageView) view.findViewById(R.id.mycode_image);
        mMycode_num_text = (TextView) view.findViewById(R.id.mycod_num_text);
    }


    @Override
    protected View getChildView() {
        View view = View.inflate(this, R.layout.activity_mycode, null);
        bindViews(view);

        return view;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }

    private UMShareListener shareListener = new UMShareListener() {
        /**
         * @descrption 分享开始的回调
         * @param platform 平台类型
         */
        @Override
        public void onStart(SHARE_MEDIA platform) {

        }

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            Toast.makeText(MyCodeActivity.this, "分享成功", Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            Toast.makeText(MyCodeActivity.this, "分享失败", Toast.LENGTH_LONG).show();
        }

        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            Toast.makeText(MyCodeActivity.this, "分享取消", Toast.LENGTH_LONG).show();
        }
    };
}
